package com.example.design.proxy.demo2;

import com.example.design.proxy.demo1.UserDao;
import com.example.design.proxy.demo1.UserDaoImp;

import java.lang.reflect.Proxy;

/**
 * 动态代理测试
 */
public class ProxyHandlerTest {
    public static void main(String[] args) {
        UserDao userDao=new UserDaoImp();       //目标对象

        ProxyHandler proxyHandler=new ProxyHandler(userDao);

        UserDao proxy= (UserDao) Proxy.newProxyInstance(UserDao.class.getClassLoader(),userDao.getClass().getInterfaces(),proxyHandler);

        System.out.println(proxy.add(10,20));

        System.out.println("===============");
        System.out.println(proxy.sub(20,5));
    }
}
